package com.aso114.project.adapter;


import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.aso114.project.R;
import com.aso114.project.bean.CityInfoBean;
import com.aso114.project.mvp.LoginSP;

import java.util.List;


public class ChoiceExamAdapter extends BaseAdapter {
        private List<CityInfoBean> mDatas = null;
        private Context mContext = null;
    private int checked = -1;//初始选择为-1，position没有-1嘛，那就是谁都不选咯
        public ChoiceExamAdapter(Context context, List<CityInfoBean> datas){
            mDatas = datas;
            mContext = context;
        }

    public void setChecked(int checked) {//设定一个选中的标志位，在activity中传入值。
        this.checked = checked;
    }
        @Override
        public int getCount() {
            return mDatas.size();
        }

        @Override
        public Object getItem(int i) {
            return mDatas.get(i);
        }

        @Override
        public long getItemId(int i) {
            return i;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            ViewHolder vh;
            if (view == null){
                vh = new ViewHolder();
                view = LayoutInflater.from(mContext).inflate(R.layout.exam_item, null);

                vh.name = (TextView)view.findViewById(R.id.exam_name);
                vh.gou = (ImageView)view.findViewById(R.id.gou);
//                vh.phone = (TextView)view.findViewById(R.id.sai_phone);

                view.setTag(vh);
            } else {
                vh = (ViewHolder)view.getTag();
            }
//            vh.id.setText(mDatas.get(i).id);
            vh.name.setText(mDatas.get(i).getAreaName());



//            vh.phone.setText(mDatas.get(i).phone);
            if (checked == i) {//如果点击的项目正好是position这一项

                /*将前面的小圆设置为选中状的图标*/
                vh.gou.setVisibility(View.VISIBLE);
            } else {

                /*将前面的小圆设置为未选中状的图标*/

                vh.gou.setVisibility(View.INVISIBLE);


            }
            if(checked==-1){
                if(LoginSP.getInstance().getUserAreaId()!=null){
                    if(LoginSP.getInstance().getUserAreaId().equals(mDatas.get(i).getAreaId())){
                        vh.gou.setVisibility(View.VISIBLE);
                    }
                }
            }



            return view;
        }

        public final class ViewHolder
        {
            public TextView id;
            public TextView name;
            public ImageView gou;
            public TextView phone;
        }
    }
